package com.wenwei.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wenwei.bean.ParkingHistoryBean;
import com.wenwei.parking.R;
import com.wenwei.utils.RogerDateUtils;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/8/21.
 */
public class ParkingRecordAdapter extends RecyclerView.Adapter<ParkingRecordAdapter.MyViewHolder> {

    private List<ParkingHistoryBean.DataBean> mList;

    public void setmList(List<ParkingHistoryBean.DataBean> list) {
        this.mList = list;
    }

    public interface CallBack{
        void onItemClick(ParkingHistoryBean.DataBean dataBean);
    }

    private CallBack mCallBack;

    public void setmCallBack(CallBack callBack){
        this.mCallBack = callBack;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_parking_record, null));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {

        holder.recordAddress.setText(mList.get(position).getParkAddr());
        holder.recordTime.setText(RogerDateUtils.getDateToHis(mList.get(position).getCreateTime()));
        holder.recordParkingTime.setText(mList.get(position).getOrderTime()+"小时");
        holder.recordParkingPrice.setText("¥"+mList.get(position).getTotalPay());

        holder.recordParkingSu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mCallBack.onItemClick(mList.get(position));
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.record_address)
        TextView recordAddress;
        @Bind(R.id.record_time)
        TextView recordTime;
        @Bind(R.id.record_parking_time)
        TextView recordParkingTime;
        @Bind(R.id.tag_1)
        TextView tag1;
        @Bind(R.id.record_parking_price)
        TextView recordParkingPrice;
        @Bind(R.id.record_parking_su)
        TextView recordParkingSu;

        public MyViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }



}
